<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${(packageStr)!''}.mapper.${(beanName)!''}Mapper">

    <resultMap type="${(packageStr)!''}.domain.${(beanName)!''}" id="${(beanName)!''}Result">
        <#list columnList as column>
            <result property="${(column.columnName)!''}"       column="${(column.columnNameLine)!''}"       />
        </#list>
    </resultMap>

    <sql id="select${(beanName)!''}">
        select  <#list columnList as column><#if column_index < columnList?size-1 >${(column.columnNameLine)!''},<#else>${(column.columnNameLine)!''}</#if></#list>
        from ${(tableName)!''}
    </sql>

    <select id="select${(beanName)!''}ById" parameterType="Long" resultMap="${(beanName)!''}Result">
        <include refid="select${(beanName)!''}"/>
        where ${r'#{'}${keyColumn.columnNameLine}${r'}'} = ${r'#{'}${keyColumn.columnName}${r'}'}
    </select>

    <select id="select${(beanName)!''}List" parameterType="${(packageStr)!''}.query.${(beanName)!''}Query" resultMap="${(beanName)!''}Result">
        <include refid="select${(beanName)!''}"/>
        where del_flag = '0'
            <#list columnList as column>
            <if test="${(column.columnName)!''} != null and ${(column.columnName)!''} != ''">
                AND ${column.columnNameLine} = ${r'#{'}${(column.columnName)!''}${r'}'}
            </if>
            </#list>
    </select>

    <insert id="insert${(beanName)!''}" parameterType="${(packageStr)!''}.domain.${(beanName)!''}">
        insert into ${(tableName)!''}
        <trim prefix="(" suffix=")" suffixOverrides=",">
        <#list columnList as column>
            <if test="${(column.columnName)!''} != null and ${(column.columnName)!''} != '' ">${(column.columnNameLine)!''}, </if>
        </#list>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
        <#list columnList as column>
            <if test="${(column.columnName)!''} != null and ${(column.columnName)!''} != ''">${r'#{'}${(column.columnName)!''}${r'}'}, </if>
        </#list>
        </trim>
    </insert>

    <update id="update${(beanName)!''}" parameterType="${(packageStr)!''}.domain.${(beanName)!''}">
        update ${(tableName)!''}
        <trim prefix="SET" suffixOverrides=",">
            <#list columnList as column>
            <if test="${(column.columnName)!''} != null and ${(column.columnName)!''} != ''">${(column.columnNameLine)!''} = ${r'#{'}${(column.columnName)!''}${r'}'}, </if>
            </#list>
        </trim>
        where ${r'#{'}${keyColumn.columnNameLine}${r'}'} = ${r'#{'}${keyColumn.columnName}${r'}'}
    </update>

    <delete id="delete${(beanName)!''}ById" parameterType="Long">
        update ${(tableName)!''} set del_flag = '1' where ${r'#{'}${keyColumn.columnNameLine}${r'}'} =  ${r'#{'}${keyColumn.columnName}${r'}'}
    </delete>

    <delete id="delete${(beanName)!''}ByIds" parameterType="Long">
        update ${(tableName)!''}  set del_flag = '1' where ${r'#{'}${keyColumn.columnNameLine}${r'}'} in
        <foreach item="${keyColumn.columnName}" collection="array" open="(" separator="," close=")">
            ${r'#{'}${keyColumn.columnName}${r'}'}
        </foreach>
    </delete>

</mapper>